<?php

abstract class MM_Controller_Admin_Action extends Mediad2_Controller_Action
{
	/**
	 * vars
	 */
	//变量--页面数据
	protected $isRedirect = true;					//页面跳转标志
	protected $uid = null;
	protected $nickname = '';
	protected $mobile = '';
	protected $email = null;
	protected $pwd = null;
	protected $user = array();
	protected $isadmin = 0;
	protected $addtime = null;
	protected $qq = "";
	protected $rolecode = '';
		
	/**
	 * 初始化
	 * @see Zend_Controller_Action::init()
	 */
	public function init()
	{	
		parent::init();
		header("Content-type:text/html;charset=utf-8");
		
		//UPLOADIFY 上传控件重新制定sessionID vincent[20130620]
		if(isset($_POST['PHPSESSID'])) {
			session_id($_POST['PHPSESSID']);
			session_start();
		}
		
		//获得登录用户信息
		$registry = Zend_Registry::getInstance();
		$haveUser = $registry->auth->hasIdentity();
		if ($haveUser) {
			//用户已登录
			//初始化登录用户信息
			$identity =  $registry->auth->getIdentity();
			$email = $identity->email;
			
			if(!empty($email)) {
				//获取用户信息
				$this->email = $email;
				$this->pwd = $identity->pwd;
				$this->uid = $identity->uid;
				$this->nickname = $identity->nickname;				
				$this->mobile = $identity->mobile;
				$this->isadmin = $identity->isadmin;
				$this->addtime = $identity->addtime;
				$this->qq = $identity->qq;
				$this->rolecode = $identity->rolecode;
								
				$this->user = array(
					"id"=>$this->uid,
					"em"=>$this->email,
					"nick"=>$this->nickname,
					"admin"=>$this->isadmin,
					"mobile"=>$this->mobile,
					"qq"=>$this->qq
				);
				$this->pageview->assign( "user", $this->user);
			}
			
		} else { //用户未登录，跳转到登录页面
			if ($this->isRedirect) {
				//TODO 用户未登陆处理
				$this->setSessionVar('errorMessage', 'notlogin');
				$this->_redirect(WEB_PATH."login");
			}
		}	
	}
	
	/**
	 * 发送错误信息到错误页面
	 *
	 * @param string $message
	 */
	protected function _error($message)
	{
		$this->pageview->assign ("errorsMessage", $message);
	
		$registry = Zend_Registry::getInstance();
		$haveUser = $registry->auth->hasIdentity();	//获得登录用户信息
		if ($haveUser) { //用户已登录
			$this->helper->setPageView ( $this->pageview, WEB_TITLE, 'errortwo', null);
		} else {
			$this->helper->setPageView ( $this->pageview, WEB_TITLE, 'error', null);
		}
		exit();
	}
	
	//---------------------------------------------------------
	// 动作
	//---------------------------------------------------------
	

}
